package com.ahmad.fvautoclicker.scrap;

import java.lang.ref.WeakReference;

public class ReferenceTest {
	public static void main(String[] args) throws InterruptedException {

		Student s1 = new Student(1);
		System.out.println(s1);
		WeakStudent ws = new WeakStudent(s1);
		System.out.println(ws.get());
		s1 = null;
		System.gc();
		Thread.sleep(1000);

		System.out.println(ws.get());

	}
}

class WeakStudent extends WeakReference<Student> {
	public WeakStudent(Student referent) {
		super(referent);
	}
}

class Student {
	public Student(int id) {
		this.id = id;
	}

	int id;

	public String toString() {

		return "[id=" + id + "]";

	}
}
